package com.timi_licai.timi_licai_account.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.timi_licai.timi_licai_account.R;
import com.timi_licai.timi_licai_account.model.KeyLineListViewModel;

import java.util.List;

/**
 * 折线图Fragment中ListView的adapter
 */
public class KeyLineListViewAdapter extends BaseAdapter {
    private List<KeyLineListViewModel> keyList;
    private Context context;

    public KeyLineListViewAdapter(Context context, List<KeyLineListViewModel> keyList) {
        this.keyList = keyList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return keyList.size();
    }

    @Override
    public Object getItem(int position) {
        return keyList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_show_key_line_list_view, parent, false);
            viewHolder.categoryTxt = (TextView) convertView.findViewById(R.id.txt_listView_show_category);
            viewHolder.feeTxt = (TextView) convertView.findViewById(R.id.txt_listView_show_num);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.categoryTxt.setText(keyList.get(position).getCategory());
        viewHolder.feeTxt.setText(keyList.get(position).getFee() + "");
        return convertView;
    }

    private class ViewHolder {
        public TextView categoryTxt;
        public TextView feeTxt;
    }
}
